﻿using System.Data;
using System.Data.OracleClient;
using DataGeneration.Domain.Logging;

namespace DataGeneration.Domain.DataAccessLayer
{
    /// <summary>
    /// Defines the type OracleInitializer
    /// </summary>
    public class OracleInitializer
    {
        /// <summary>
        /// Initializes the command.
        /// </summary>
        /// <param name="commandName">Name of the command.</param>
        /// <param name="commandType">Type of the command.</param>
        /// <param name="connection">The connection.</param>
        /// <returns></returns>
        public static IDbCommand InitializeCommand(string commandName, CommandType commandType,IDbConnection connection)
        {
            return new OracleCommand(commandName, (OracleConnection)connection) { CommandType = commandType };
        }

        /// <summary>
        /// Opens the connection.
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <returns></returns>
        public static IDbConnection OpenConnection(string connectionString)
        {
            var connection = new OracleConnection(connectionString);
            connection.Open();
            Logger.WriteMessage("Connection successfully opened!");
            return connection;
        }
    }
}